<!DOCTYPE HTML>
<html>

<head>
	<meta charset="utf-8">
	<title>添加地址</title>
	<meta name="keywords" content="KEYWORDS...">
	<meta name="description" content="DESCRIPTION...">
	<meta name="author" content="DeathGhost">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-touch-fullscreen" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="format-detection" content="telephone=no">
	<meta name="format-detection" content="address=no">
	<meta name="viewport" content="initial-scale=1, width=device-width, maximum-scale=1, user-scalable=no">
	<link rel="stylesheet" type="text/css" href="../../css/my/cydz/CityPicker.css">

	<style>
	body{
	  background-color: #fcfcfc;
	  height:100%;
	  padding-top:40px;
	}
	.header{
	 width: 100%;height:40px;
	}
	.leftreturn{
	 width:25px;
	 height:25px;
	 margin:7.5px;
	 float: left;
	}
	.formarea li a {
	 line-height: 0.74rem;
	 color: #989898;
	}

	.formarea li {
	 height: 0.8rem;
	 padding: 1% 2%;
	 background: #fff;
	 border-bottom: 1px solid #ccc;
	}
	.formarea li input {
	 line-height: 0.74rem;
	}
	input{
	 border: none;
	 outline: none;
	 font-size: 16px;
	 color: #989898;
	}

	.save{
	 float: right;
	 line-height: 40px;
	 margin-right: 20px;
	 color: #000080
	}

	</style>
</head>

<body style="width: 100%;overflow-x: hidden;">
	<div class="header">
		<a href="cydz.html"><img src="../../image/leftreturn.png" alt="" class="leftreturn"></a>
		<!-- <span class="save"  onclick="submit();">保存</span>
		<script type="text/javascript">
		      // function submit(){
		          alert('保存成功');
		      } -->
		</script>
	</div>
	<ul class="formarea">
		<li><input id="consignee" name="" type="text" value="收货人"onfocus="if (value =='收货人'){value =''}" onblur="if (value ==''){value='收货人'}"/></li>
		<li>
			<input id="mobile"  name="" type="text" value="手机号码"onfocus="if (value =='手机号码'){value =''}" onblur="if (value ==''){value='手机号码'}"/>
			</li>
		<li>
			<label class="lit">所在地区</label>
			<input id="location"  name="" type="text" value="省份城市"onfocus="if (value =='省份城市'){value =''}" onblur="if (value ==''){value='省份城市'}"/>
		</li>
		<li>
			<input id="detailaddress"  name="" type="text" value="详细地址：如道路、门牌、小区楼栋等"onfocus="if (value =='详细地址：如道路、门牌、小区楼栋等'){value =''}" onblur="if (value ==''){value='详细地址：如道路、门牌、小区楼栋等'}"/>
		</li>
		<li>
			<input type="submit" value="提交"  tapmode="highlight" onclick="alteraddress();">&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="reset" name="重置">		</li>
	</ul>
	<div style="height:1.2rem;"></div>
</body>
<script src="../../css/my/cydz/picker.min.js"></script>
<script src="../../css/my/cydz/city.js"></script>
<script type="text/javascript" src="../../script/SHA1.js"></script>
<script type="text/javascript" src="../../script/api.js"></script>
<script>

	 function alteraddress(){
		 var consignee=document.getElementById('consignee').value;
		var mobile=document.getElementById('mobile').value;
		var location=document.getElementById('location').value;
		var detailaddress=document.getElementById('detailaddress').value;

		//获取已登入用户id
		user= $api.getStorage('user');

		//获取X-APICloud-AppKey值
		var now = Date.now();
		appKey = SHA1("A6032422409194"+"UZ"+"808CF36B-60D4-DC5D-C9F3-FB49F9E1FB44"+"UZ"+now)+"."+now

		api.ajax({
				url: "https://d.apicloud.com/mcm/api/user/"+user[0].id+"/address",
				method: 'POST',
				cache:  false,
				headers:{
					"X-APICloud-AppId": "A6032422409194",
					"X-APICloud-AppKey": appKey
				},
				data:{
					values: {
					 "consignee":consignee,
					"mobile":mobile,
					"location":location,
					"detailaddress":detailaddress
									}
				}

		},function(ret, err){
				if (ret) {
					  user[0].address[user[0].address.length]=ret;
						$api.setStorage('user', user);
						api.alert({
								title: '信息',
								msg: '地址添加成功',
						}, function(ret, err){});

						api.sendEvent({
						    name: 'csdz',
						    extra: {
						        user: user
						    }
						});

						api.closeWin();
				} else {
						api.alert({
								title: '警告',
								msg: '数据库连接失败',
						}, function(ret, err){});
				}
		});

}
</script>

</html>
